<?php
/* 	These code was generated using phpCIGen v 0.1.b (24/06/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id
	
	+ Module  		: t_bbmrec Print
	+ Description	: For Print View
	+ Filename 		: p_t_bbmrec.php
 	+ Author  		: 
 	+ Created on 07/Jun/2011 11:52:07
	
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laporan Tagihan</title>
<link rel='stylesheet' type='text/css' href='../assets/modules/main/css/printstyle_nocolor.css'/>
</head>
<body onload="window.print();">
<?php 
$tgl_before = "";
$customer_before = "";
$orderdet_id_before = 0;
$tgl = array();

$customer_name_bytgl[] = array();
$det_bycust[][] = array();

$i = 0;

foreach ($data_print as $row){
	$i++;

	if((in_array($row->bill_date, $tgl))==false){
		$tgl_before = $row->bill_date;
		$customer_before = $row->customer_name;
		$orderdet_id_before = $row->orderdet_id;
		$tgl[$i] = $row->bill_date;
		$i++;

		$i_customer_bytgl = 0;
		$i_det_bycust = 0;

		$customer_name_bytgl[$tgl_before][$i_customer_bytgl] = $customer_before;
		
		$det_bycust[$tgl_before][$customer_before][$i_det_bycust] = $orderdet_id_before;

	}else if($row->bill_date == $tgl_before){

		if((in_array($row->customer_name, $customer_name_bytgl[$tgl_before])) == false){
			$i_customer_bytgl++;
			$i_det_bycust = 0;

			$customer_before = $row->customer_name;
			$orderdet_id_before = $row->orderdet_id;

			$customer_name_bytgl[$tgl_before][$i_customer_bytgl] = $customer_before;
			$det_bycust[$tgl_before][$customer_before][$i_det_bycust] = $orderdet_id_before;

		}elseif((in_array($row->customer_name, $customer_name_bytgl[$tgl_before])) && (!(in_array($row->orderdet_id, $det_bycust[$tgl_before][$customer_before])))){
			$i_det_bycust++;

			$det_bycust[$tgl_before][$customer_before][$i_det_bycust] = $row->orderdet_id;
		}
	}
}
?>
<table width="100%" border="0" class="clear">
  <tr class="clear" >
    <td height="38" colspan="4" class="clear" align="center"><strong>Laporan Penjualan</strong></td>
  </tr>
  <tr class="clear" >
  	<td height="38" colspan="4" class="clear" align="center"><strong><?php echo $tgl_start;?><br/><?php echo $tgl_end;?></strong></td>
  </tr>
</table>
<table width="100%" border="1">
	<thead>
		<tr style="font-weight: bold;">
			<td scope='col'>TGL</td>
			<td scope='col'>KLIEN</td>
			<td scope='col'>NO.KW</td>
			<td scope='col'>BNYK</td>
			<td scope='col'>ORDER</td>
			<td scope='col'>HARGA @</td>
			<td scope='col'>JUMLAH</td>
			<td scope='col'>TOTAL</td>
		</tr>
	</thead>
	<tbody>
		<?php 
		for($i_tgl=0; $i_tgl<(sizeof($tgl)); $i_tgl++){
		?>
		<tr>
			<td class="left_axis" rowspan="<?php echo sizeof($customer_name_bytgl[$tgl[$i_tgl]]);?>"><?php echo $tgl[$i_tgl];?></td>
		<?php 
				for($i_cust=0; $i_cust<(sizeof($customer_name_bytgl[$tgl[$i_tgl]])); $i_cust++){
					if($i_cust>0){echo '<tr>';}
		?>
			<td class="left_axis" rowspan="<?php echo sizeof($customer_name_bytgl[$tgl[$i_tgl]][$i_cust]);?>"><?php echo $customer_name_bytgl[$tgl[$i_tgl]][$i_cust];?></td>
		<?php 
					$total = 0;
					$i_det = 0;
					foreach ($data_print as $row){
						if(($row->bill_date == $tgl[$i_tgl]) 
						&& ($row->customer_name == $customer_name_bytgl[$tgl[$i_tgl]][$i_cust]) ){
							$i_det++;
		?>
			<td align="left"><?php echo $row->bill_no;?></td>
			<td align="right"><?php echo $row->orderdet_qty;?></td>
			<td align="left"><?php echo $row->orderdet_detail;?></td>
			<td align="right"><?php echo $row->orderdet_price;?></td>
			<td align="right"><?php echo $row->jumlah;?></td>
		<?php 
							$total += $row->jumlah;
						}
					}
					if($i_det>1){
						$i_det -= 1;
					}
		?>
		<td align="right" rowspan="<?php echo $i_det;?>"><?php echo $total;?></td>
		<?php 
					
					if($i_cust==((sizeof($customer_name_bytgl[$tgl[$i_tgl]])) - 1)){echo '</tr>';}
				}
		?>
		</tr>
		<?php 
		}
		?>
	</tbody>
</table>
</body>
</html>